<template>
  <el-dialog v-model="visible" :title="!dataForm.psjId ? $t('add') : $t('update')" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="rules" ref="dataFormRef" @keyup.enter="dataFormSubmitHandle()" label-width="120px">
      <el-form-item label="" prop="psjId">
        <el-input v-model="dataForm.psjId" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjName">
        <el-input v-model="dataForm.psjName" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjFirstEName">
        <el-input v-model="dataForm.psjFirstEName" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjLastEName">
        <el-input v-model="dataForm.psjLastEName" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjGender">
        <el-input v-model="dataForm.psjGender" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjComName">
        <el-input v-model="dataForm.psjComName" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjComEName">
        <el-input v-model="dataForm.psjComEName" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjTrade">
        <el-input v-model="dataForm.psjTrade" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjLevel">
        <el-input v-model="dataForm.psjLevel" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjJoinType">
        <el-input v-model="dataForm.psjJoinType" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjType">
        <el-input v-model="dataForm.psjType" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjCountryCode">
        <el-input v-model="dataForm.psjCountryCode" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjCityCode">
        <el-input v-model="dataForm.psjCityCode" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjContinent">
        <el-input v-model="dataForm.psjContinent" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjCountry">
        <el-input v-model="dataForm.psjCountry" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjArea">
        <el-input v-model="dataForm.psjArea" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjProvince">
        <el-input v-model="dataForm.psjProvince" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjCity">
        <el-input v-model="dataForm.psjCity" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjDistrict">
        <el-input v-model="dataForm.psjDistrict" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjWebUrl">
        <el-input v-model="dataForm.psjWebUrl" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjEmail">
        <el-input v-model="dataForm.psjEmail" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjEmail1">
        <el-input v-model="dataForm.psjEmail1" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjAddress">
        <el-input v-model="dataForm.psjAddress" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjEAddress">
        <el-input v-model="dataForm.psjEAddress" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjMobile">
        <el-input v-model="dataForm.psjMobile" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjMobile1">
        <el-input v-model="dataForm.psjMobile1" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjTel">
        <el-input v-model="dataForm.psjTel" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjTel1">
        <el-input v-model="dataForm.psjTel1" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjTel2">
        <el-input v-model="dataForm.psjTel2" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjQq">
        <el-input v-model="dataForm.psjQq" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjFax">
        <el-input v-model="dataForm.psjFax" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjFax1">
        <el-input v-model="dataForm.psjFax1" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjFax2">
        <el-input v-model="dataForm.psjFax2" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjOtherLinkInfo">
        <el-input v-model="dataForm.psjOtherLinkInfo" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjZipCode">
        <el-input v-model="dataForm.psjZipCode" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjRank">
        <el-input v-model="dataForm.psjRank" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjERank">
        <el-input v-model="dataForm.psjERank" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjDept">
        <el-input v-model="dataForm.psjDept" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjEDept">
        <el-input v-model="dataForm.psjEDept" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjUnifyRank">
        <el-input v-model="dataForm.psjUnifyRank" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjUnifyDept">
        <el-input v-model="dataForm.psjUnifyDept" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjIdCard">
        <el-input v-model="dataForm.psjIdCard" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psnId">
        <el-input v-model="dataForm.psnId" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjIfFirst">
        <el-input v-model="dataForm.psjIfFirst" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjRemark">
        <el-input v-model="dataForm.psjRemark" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjExtField1">
        <el-input v-model="dataForm.psjExtField1" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjExtField2">
        <el-input v-model="dataForm.psjExtField2" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="creatorId">
        <el-input v-model="dataForm.creatorId" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="modifierId">
        <el-input v-model="dataForm.modifierId" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="deleterId">
        <el-input v-model="dataForm.deleterId" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjGroup">
        <el-input v-model="dataForm.psjGroup" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjQuality">
        <el-input v-model="dataForm.psjQuality" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjSource">
        <el-input v-model="dataForm.psjSource" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjPreExhId">
        <el-input v-model="dataForm.psjPreExhId" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjRestDay">
        <el-input v-model="dataForm.psjRestDay" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjRestTime">
        <el-input v-model="dataForm.psjRestTime" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjVisibility">
        <el-input v-model="dataForm.psjVisibility" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjVisitorCard">
        <el-input v-model="dataForm.psjVisitorCard" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjCurrentCard">
        <el-input v-model="dataForm.psjCurrentCard" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjAnswer">
        <el-input v-model="dataForm.psjAnswer" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjComTradeKey1">
        <el-input v-model="dataForm.psjComTradeKey1" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjComTradeKey2">
        <el-input v-model="dataForm.psjComTradeKey2" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjComNameKey">
        <el-input v-model="dataForm.psjComNameKey" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjComCityKey">
        <el-input v-model="dataForm.psjComCityKey" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjComModelKey">
        <el-input v-model="dataForm.psjComModelKey" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjSysState">
        <el-input v-model="dataForm.psjSysState" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjCreateTime">
        <el-input v-model="dataForm.psjCreateTime" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjFlag">
        <el-input v-model="dataForm.psjFlag" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjIfTreatKey">
        <el-input v-model="dataForm.psjIfTreatKey" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjIfTreatRepeat">
        <el-input v-model="dataForm.psjIfTreatRepeat" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjIfTreatCom">
        <el-input v-model="dataForm.psjIfTreatCom" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjIfTelChk">
        <el-input v-model="dataForm.psjIfTelChk" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjIfFaxChk">
        <el-input v-model="dataForm.psjIfFaxChk" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjIfMailChk">
        <el-input v-model="dataForm.psjIfMailChk" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjIfMobChk">
        <el-input v-model="dataForm.psjIfMobChk" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjIfAddChk">
        <el-input v-model="dataForm.psjIfAddChk" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjVoucherId">
        <el-input v-model="dataForm.psjVoucherId" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="comId">
        <el-input v-model="dataForm.comId" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="atrId">
        <el-input v-model="dataForm.atrId" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjVoucherType">
        <el-input v-model="dataForm.psjVoucherType" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjLanguage">
        <el-input v-model="dataForm.psjLanguage" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjMsn">
        <el-input v-model="dataForm.psjMsn" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjIfReceive">
        <el-input v-model="dataForm.psjIfReceive" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjBsn">
        <el-input v-model="dataForm.psjBsn" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjBsntxt">
        <el-input v-model="dataForm.psjBsntxt" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjLagCode">
        <el-input v-model="dataForm.psjLagCode" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjPostAddress">
        <el-input v-model="dataForm.psjPostAddress" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjEAddress2">
        <el-input v-model="dataForm.psjEAddress2" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjEAddress3">
        <el-input v-model="dataForm.psjEAddress3" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjEAddress4">
        <el-input v-model="dataForm.psjEAddress4" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjSurName">
        <el-input v-model="dataForm.psjSurName" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjLastName">
        <el-input v-model="dataForm.psjLastName" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjInviteCode">
        <el-input v-model="dataForm.psjInviteCode" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjIfPostCard">
        <el-input v-model="dataForm.psjIfPostCard" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjWeixin">
        <el-input v-model="dataForm.psjWeixin" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="groupId">
        <el-input v-model="dataForm.groupId" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjGroupId">
        <el-input v-model="dataForm.psjGroupId" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjAnswersNum">
        <el-input v-model="dataForm.psjAnswersNum" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjAnswersTitle">
        <el-input v-model="dataForm.psjAnswersTitle" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjRegCountry">
        <el-input v-model="dataForm.psjRegCountry" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjMiddleEName">
        <el-input v-model="dataForm.psjMiddleEName" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjAntionality">
        <el-input v-model="dataForm.psjAntionality" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjAlipay">
        <el-input v-model="dataForm.psjAlipay" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjCounty">
        <el-input v-model="dataForm.psjCounty" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjSex">
        <el-input v-model="dataForm.psjSex" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjPhoto">
        <el-input v-model="dataForm.psjPhoto" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjEmployeescard">
        <el-input v-model="dataForm.psjEmployeescard" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psndaltetime">
        <el-input v-model="dataForm.psndaltetime" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="" prop="psjMainProduct">
        <el-input v-model="dataForm.psjMainProduct" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="删除标记 0未删除，1已删除" prop="delFlag">
        <el-input v-model="dataForm.delFlag" placeholder="删除标记 0未删除，1已删除"></el-input>
      </el-form-item>
    </el-form>
    <template v-slot:footer>
      <el-button @click="visible = false">{{ $t("cancel") }}</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">{{ $t("confirm") }}</el-button>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { reactive, ref } from "vue";
import baseService from "@/service/baseService";
import { useI18n } from "vue-i18n";
import { ElMessage } from "element-plus";
const { t } = useI18n();
const emit = defineEmits(["refreshDataList"]);

const visible = ref(false);
const dataFormRef = ref();

const dataForm = reactive({
  psjId: "",
  psjName: "",
  psjFirstEName: "",
  psjLastEName: "",
  psjGender: "",
  psjComName: "",
  psjComEName: "",
  psjTrade: "",
  psjLevel: "",
  psjJoinType: "",
  psjType: "",
  psjCountryCode: "",
  psjCityCode: "",
  psjContinent: "",
  psjCountry: "",
  psjArea: "",
  psjProvince: "",
  psjCity: "",
  psjDistrict: "",
  psjWebUrl: "",
  psjEmail: "",
  psjEmail1: "",
  psjAddress: "",
  psjEAddress: "",
  psjMobile: "",
  psjMobile1: "",
  psjTel: "",
  psjTel1: "",
  psjTel2: "",
  psjQq: "",
  psjFax: "",
  psjFax1: "",
  psjFax2: "",
  psjOtherLinkInfo: "",
  psjZipCode: "",
  psjRank: "",
  psjERank: "",
  psjDept: "",
  psjEDept: "",
  psjUnifyRank: "",
  psjUnifyDept: "",
  psjIdCard: "",
  psnId: "",
  psjIfFirst: "",
  psjRemark: "",
  psjExtField1: "",
  psjExtField2: "",
  creatorId: "",
  modifierId: "",
  deleterId: "",
  psjGroup: "",
  psjQuality: "",
  psjSource: "",
  psjPreExhId: "",
  psjRestDay: "",
  psjRestTime: "",
  psjVisibility: "",
  psjVisitorCard: "",
  psjCurrentCard: "",
  psjAnswer: "",
  psjComTradeKey1: "",
  psjComTradeKey2: "",
  psjComNameKey: "",
  psjComCityKey: "",
  psjComModelKey: "",
  psjSysState: "",
  psjCreateTime: "",
  psjFlag: "",
  psjIfTreatKey: "",
  psjIfTreatRepeat: "",
  psjIfTreatCom: "",
  psjIfTelChk: "",
  psjIfFaxChk: "",
  psjIfMailChk: "",
  psjIfMobChk: "",
  psjIfAddChk: "",
  psjVoucherId: "",
  comId: "",
  atrId: "",
  psjVoucherType: "",
  psjLanguage: "",
  psjMsn: "",
  psjIfReceive: "",
  psjBsn: "",
  psjBsntxt: "",
  psjLagCode: "",
  psjPostAddress: "",
  psjEAddress2: "",
  psjEAddress3: "",
  psjEAddress4: "",
  psjSurName: "",
  psjLastName: "",
  psjInviteCode: "",
  psjIfPostCard: "",
  psjWeixin: "",
  groupId: "",
  psjGroupId: "",
  psjAnswersNum: "",
  psjAnswersTitle: "",
  psjRegCountry: "",
  psjMiddleEName: "",
  psjAntionality: "",
  psjAlipay: "",
  psjCounty: "",
  psjSex: "",
  psjPhoto: "",
  psjEmployeescard: "",
  psndaltetime: "",
  psjMainProduct: "",
  delFlag: "",
});

const rules = ref({
});

const init = (psjId?: number) => {
  visible.value = true;
  dataForm.psjId = "";

  // 重置表单数据
  if (dataFormRef.value) {
    dataFormRef.value.resetFields();
  }

  if (psjId) {
    getInfo(psjId);
  }
};

// 获取信息
const getInfo = (psjId: number) => {
  baseService.get("/crm/crmpersonjoin/" + psjId).then((res) => {
    Object.assign(dataForm, res.data);
  });
};

// 表单提交
const dataFormSubmitHandle = () => {
  dataFormRef.value.validate((valid: boolean) => {
    if (!valid) {
      return false;
    }
    (!dataForm.psjId ? baseService.post : baseService.put)("/crm/crmpersonjoin", dataForm).then((res) => {
      ElMessage.success({
        message: t("prompt.success"),
        duration: 500,
        onClose: () => {
          visible.value = false;
          emit("refreshDataList");
        }
      });
    });
  });
};

defineExpose({
  init
});
</script>